import UIKit

var str = "Hello, playground"
print(str)

let letStr = "李彦宏"

var jointStr = letStr + str

//??设置默认值
// ? 可以为空
var nickname: String? = nil
nickname = "Wo"
let fullName: String = "Robin Li"
let informalGreeting = "Hi \(nickname ?? "")\(fullName)"

//for 循环
for intItem in 1...4 {
    if intItem == 1{
    print("value=\(intItem)Hong超棒")
    }
    
    if intItem == 2 {
       break
    }
    if intItem == 3 {
        print("哦豁=\(intItem)")
    }
}

//swith  case 可以是

let swithValue = "Li YanHong"

switch swithValue {
case "Li":
    print("Li")
case let x where x.hasSuffix("YanHong"): //where语句 限定某些条件
    print(swithValue)
default:
    print("YanHong")
}

//函数
func getName(xing: String, ming: String) -> (xing: String, ming: String){
    return (xing,ming)
}
getName(xing: "Li", ming: "YanHong")
print(getName(xing: "Li", ming: "YanHong").xing)
var xingStr = getName(xing: "Li", ming: "YanHong").xing
var mingStr = getName(xing: "Li", ming: "YanHong").ming



//闭包
var numbers = [20, 19, 7, 12]
// 函数实际上是一种特殊的闭包，它是一段能之后被调取的代码， 你可以说使用{}来创建一个匿名闭包， 使用in将参数和返回值类型的声明与闭包函数体进行分离,
numbers.map({
    (number: Int) ->Int in
    let result = 3 * number
    return result
})
// 如果一个闭包的类型已知，比如作为一个代理的回调，你可以忽略参数、返回值，甚至两个都忽略
let mappedNumbers = numbers.map({number in 3 * number})
print(mappedNumbers)
// 当一个闭包作为最后一个参数传给一个函数的时候，它可以直接跟着括号后面，当一个闭包是传给函数的唯一参数，你可以完成忽略括号
let sortedNumbers = numbers.sorted{$0 > $1}
print(sortedNumbers)


//对象与类
class Shape{
    var shapeValue = 0
    func simpleDescription() -> String {
        return "A shape with \(shapeValue) sides."
    }
    
}
var shape = Shape()
shape.shapeValue = 7
var shapeDescription = shape.simpleDescription()

//枚举
//原始值
enum DaysofaWeek: Int{
    case Sunday = 1 //周日
    case Monday
    case TUESDAY
    case WEDNESDAY
    case THURSDAY
    case FRIDAY
    case Saturday //周六
}
var weekDay = DaysofaWeek.TUESDAY

switch weekDay {
case .TUESDAY:
    print("星期二")
default:
    print("不知道")
}


// 相关值
enum Student{
    case Name(String)
    case Mark(Int,Int,Int)
}

var studDetails = Student.Name("StudentHong")
var studMarks = Student.Mark(98,97,95)

switch studDetails {
case .Name(let studName):
    print("学生的名字是: \(studName)。")
default:
    print("学生的名字是XXX")
}

//结构体
struct Card {
    var student : Student
    var sofaWeek : DaysofaWeek
    
}
